package com.sise.stuteaintersys.mapper;

import com.sise.stuteaintersys.bean.entity.Course;
import com.sise.stuteaintersys.bean.entity.CourseExample;
import com.sise.stuteaintersys.bean.vo.element.CourseIndexResponseVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;


import java.util.List;

@Component
public interface CourseMapper {
    int countByExample(CourseExample example);

    int deleteByExample(CourseExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(Course record);

    int insertSelective(Course record);

    List<CourseIndexResponseVO> selectByExample(CourseExample example);

    /**
     * 查询所有课程信息
     * @return
     */
    @Select("SELECT * FROM course")
    List<Course> selectAllCourse();

    /**
     * 根据课程名称进行模糊查询
     * @return
     */
    @Select("SELECT * FROM course WHERE course.name LIKE concat(concat('%',#{courseName}),'%')")
    List<Course> selectFuzzyCourse(String courseName);

    /**
     * 根据课程名称进行查询
     * @param courseName
     * @return
     */
    @Select("SELECT * FROM course WHERE course.name = #{courseName}")
    List<Course> selectCourseByName(String courseName);

    /**
     * 根据课程分类名称进行查找
     * @param courseTypeName
     * @return
     */
    @Select("SELECT * FROM course WHERE course.type_name = #{courseTypeName}")
    List<Course> selectCourseByCourseTypeName(String courseTypeName);

    /**
     * 根据id查询课程信息
     * @param id
     * @return
     */
    Course selectByPrimaryKey(Integer id);

    /**
     * 根据课程分类进行删除
     * @param typeName
     * @return
     */
    @Delete("DELETE FROM course WHERE course.type_name = #{typeName}")
    int deleteByCourseTypeName(String typeName);


    /**
    * 查找
    *@param name
    *@return 
    *@date 2018/12/29
    *@time 14:29
    */
    @Select("select * from course where profession_name=#{name} and deadline < CURDATE() limit 5")
    List<Course> selectByProfessionName(String name);

    /**
     * 根据课程名称进行模糊查询
     * *@param courseName
     * @return
     */
    @Select("SELECT * FROM course WHERE course.name LIKE concat(concat('%',#{courseName}),'%')")
    List<CourseIndexResponseVO> selectLikeCourse(String courseName);

    /**
     * 根据老师名称进行模糊查询
     * *@param courseName
     * @return
     */
    @Select("SELECT * FROM course WHERE course.teacher_name LIKE concat(concat('%',#{teacherName}),'%')")
    List<CourseIndexResponseVO> selectFuzzyTeacher(String teacherName);


    /**
     * 根据专业分向名称查询
     * *@param courseName
     * @return
     */
    @Select("select * from course where course.profession_name=#{professionName}")
    List<CourseIndexResponseVO> selectCourseByProfession(String professionName);

    /**
     * 根据课程类型查询
     * *@param TypeName
     * @return
     */
    @Select("select * from course where course.type_name=#{type_Name}")
    List<CourseIndexResponseVO> selectCourseByType(String TypeName);


    /**
     *  搜索
     *
     *@param course
     *@return List<Course>
     *@date 2019/1/6
     *@time 11:22
     */
    List<Course> selectCourse(Course course);


    /**
     * 根据老师ID查询
     * *@param teacherName
     * @return
     */
    @Select("select * from course where teacher_id=#{teacherId} and deadline >= CURDATE()")
    List<Course> selectCourseByTeacherId(Integer teacherId);


    @Select("select * from course where teacher_id=#{teacherId} and deadline < CURDATE()")
    List<Course> selectFinishedCourse(Integer teacherId);

    /**
     * 学生正在学习的课程
     *
     *@param id
     *@return List<Course>
     */
    @Select("select * from course where id in (select course_id from student_course where student_id=#{id}) and deadline >= CURDATE()")
    List<Course> listCourse(Integer id);

    /**
     * 学生已经学完的课程
     *
     *@param id
     *@return List<Course>
     */
    @Select("select * from course where id in (select course_id from student_course where student_id=#{id}) and deadline < CURDATE()")
    List<Course> finishedCourse(Integer id);


    int updateByExampleSelective(@Param("record") Course record, @Param("example") CourseExample example);

    int updateByExample(@Param("record") Course record, @Param("example") CourseExample example);

    int updateByPrimaryKeySelective(Course record);

    int updateByPrimaryKey(Course record);
}